	Invoking and interacting with a .NET application from VEE 7.0

What can VEE 7.0 do with .NET application?
------------------------------------------

Although VEE 7.0 cant embed .NET Visual Controls as it can ActiveX Controls, it can easily interact with the public members of a .NET application. It can 
-	start the .NET application
-	read and set values of .NET interface elements (or other public variables) such as trackbars or textboxes
-	detect when the application has terminated

VEE 7 can only interact with the .NET application programmatically; it cannot set up event handlers for it.

What is this example and what do I need to use it?
--------------------------------------------------

Ive provided in this example a simple application written in VB .NET. It has a textbox for input, two trackbars, one of which is controlled by the .NET applications interface, and the other by VEE. The .NET application can control parts of the VEE application and the VEE application can control parts of the .NET application

You can edit the .NET application and play with it. To re-build it, youll need Visual Studio .NET, or VB .NET Standard Edition (Well, if you are pure of heart and have the strength of 10 programmers, you can do this from a command prompt, but I dont describe that here). You dont need the Agilent T&M Programmers Toolkit for Visual Studio .NET, though theres nothing to prevent you from using the Toolkits classes in the application. Youll also need VEE Pro 7.0 or later; it wont work in earlier revisions.

Basic operation
---------------

Unpack the zip file into a convenient place. Double click VB_test_dotnet.vee to start it in VEE 7.0 or later.

If you click VEEs Run button, the application will probably fail. In that case, go to VEEs Device menu > .NET Assembly References Check the end of the list of assemblies for whether WindowsApplication2 is there and selected or not. If its there and not selected, select it and OK out of the dialog. If its not there, click browse and find the file WindowsApplication2.exe in either the bin or the obj subdirectory of the unpacked zip. When youre back in the main dialog, make sure WindowsApplication2 is checked. If it still fails after this, see below.

Once setup is complete, you can run the VEE application. It will pop up a small .NET application form that you can interact with. 

As you drag the .NET apps top trackbar (slider) youll be able to see the VEE Alphanumeric object with the green titlebar display the same value as the trackbar is set to. 

If you edit the text in the textbox, youll see it in the VEE Alphanumeric display with the putrid pink titlebar. 

Try as you might, you wont be able to drag the bottom trackbar around in the .NET application while the VEE program is running. Thats because VEE is continually setting the lower trackbar to the value on the Int32  slider in the VEE program. Move the Int32 slider around and watch.

If you click the close box (x in upper right corner) of the .NET app, itll disappear, and the VEE program will stop.

What needs to be done to get this all working for a new .NET application?
-------------------------------------------------------------------------

You need to build a .NET app that does what you want it to and has Windows forms widgets in it (you dont absolutely need the widgets, but theyre more fun). Once youve built and tested it, youre ready to make some minor customizations:

-	youll need to find the statements that declare the trackbars, etc, near the top of the VB (or C#) source code that you want VEE to know about 
Example:
    		Friend WithEvents Label1 As System.Windows.Forms.Label
Change this to
    		Public WithEvents Label1 As System.Windows.Forms.Label

Change to Public all the things you want VEE to interact with, then rebuild the app and make sure it still works (without involving VEE yet)

-	if you already have a .vee (e.g. this example) that interacts with the .NET application, go to the directory containing the .vee and delete the .exe file for your .NET application that you see there (if its not there, dont worry)

-	now before you run your .vee (or if you created a brand new .vee), select Device menu > .NET Assembly References, and use the browse button to find the rebuilt .exe. Be sure its selected it in the list in the main dialog after you click Open, and also import the namespace for it so your formulas are shorter. Youll need to delete the .exe and reselect it every time you change and rebuild it as far as I know.

You should be ready now to try it with your existing .vee program, or build a new VEE program to interact with it. Its mostly pretty self-explanatory from here on, though you may find it hard to get the correct parameter types for some methods or properties.

Why did we have to delete the exe and reselect after changing the .NET app?
---------------------------------------------------------------------------

When you browse to an unregistered assembly like your own .NET application, VEE makes a copy of it in the same directory as the .vee file. If you later make changes using VS .NET and rebuild, they only affect the copy in the development directory, not the one that was copied into the directory with the .vee.

The advantage of browsing to the .exe is that its pretty simple compared to getting it into the GAC, where it would show up in the References list. If you get serious about deploying .NET applications, youll want to at least understand how the GAC works, maybe make the effort to build the .NET application so its trusted.
